package com.asdhawaii.otello.players;

import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import com.asdhawaii.otello.board.Move;
import com.asdhawaii.otello.board.Square;
import com.asdhawaii.otello.board.SquareContents;

/**
 * Tests the Level 5 AI.
 * 
 * @author Branden Ogata
 *
 */

public class TestLevel5Ai extends TestAbstractOtelloAi
{
  /**
   * Tests that the Level 5 AI behaves as expected.
   * 
   */
  
  @Test
  public void test()
  {
    Level5Ai ai = new Level5Ai(SquareContents.BLACK);
    Square[][] board = createEmptyBoard();
    List<Move> validMoves = new ArrayList<Move>();
    
    // ?
    //  W
    //   B
    // ?  W
    // WW  ?
    // W B  B ?
    // W   W  W
    // BWW?   B
    board[1][1].setContents(SquareContents.WHITE);
    board[2][2].setContents(SquareContents.BLACK);
    board[3][3].setContents(SquareContents.WHITE);
    board[4][0].setContents(SquareContents.WHITE);
    board[4][1].setContents(SquareContents.WHITE);
    board[5][0].setContents(SquareContents.WHITE);
    board[5][2].setContents(SquareContents.BLACK);
    board[5][5].setContents(SquareContents.BLACK);
    board[6][0].setContents(SquareContents.WHITE);
    board[6][4].setContents(SquareContents.WHITE);
    board[6][7].setContents(SquareContents.WHITE);
    board[7][0].setContents(SquareContents.BLACK);
    board[7][1].setContents(SquareContents.WHITE);
    board[7][2].setContents(SquareContents.WHITE);
    board[7][7].setContents(SquareContents.BLACK);
    
    TestAbstractOtelloAi.createList(validMoves, new Move(0, 0), new Move(3, 0), new Move(4, 4), 
                                                new Move(5, 7), new Move(7, 3));
    
    // Should play the corner first
    assertEquals("Plays corner move", new Move(0, 0), ai.getMove(board, validMoves));
    
    // After that, plays a stable move
    board[0][0].setContents(SquareContents.BLACK);
    board[1][1].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(0, 0));
    assertEquals("Plays stable move", new Move(5, 7), ai.getMove(board, validMoves));
    
    // After that, plays the most stable move
    board[5][7].setContents(SquareContents.BLACK);
    board[6][7].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(5, 7));
    assertEquals("Plays partial stable move", new Move(3, 0), ai.getMove(board, validMoves));
    
    // The remaining behavior is identical to Level3Ai, so will not need to test here
  }
}